﻿using System;
using System.Collections.Generic;
using System.IO;
using NQUnit;
using NUnit.Framework;

namespace OpenWaves.ActivityFeed.Web.Tests.UnitTests
{
    [TestFixture]
    public class QUnitTests
    {
        public QUnitTests()
        {
            global::NQUnit.NQUnit.ClearCacheBeforeRunningTests = true;
        }

        [Test, TestCaseSource("GetQUnitTests")]
        public void Test(QUnitTest test)
        {
            if (test.InitializationException != null)
                throw new Exception("The QUnit initialization failed.", test.InitializationException);

            Assert.That(test.Result, Is.EqualTo("pass"), "Test: " + test.TestName + Environment.NewLine + test.Message);
        }

        public IEnumerable<QUnitTest> GetQUnitTests()
        {
            var testsDirectory = Path.Combine(Environment.CurrentDirectory, "..", "UnitTests");
            IEnumerable<QUnitTest> result =  global::NQUnit.NQUnit.GetTests(Directory.GetFiles(testsDirectory, "*.html"));
            return result;
        }
    }
}